<?php
ob_start();
session_start();
date_default_timezone_set('Asia/Bangkok');
$department = $_SESSION["departid"];


	include "../connect.php";
	$strSQL = "SELECT * FROM employee INNER JOIN mail ON employee.emp_id = mail.emp_id INNER JOIN depart ON employee.de_id = depart.id where employee.emp_id = '".$_POST["sCusID"]."' AND depart.departid = '$department' ";
	$objQuery = mysql_query($strSQL) or die (mysql_error());
	if(mysql_num_rows($objQuery) > 0){
			$intNumField = mysql_num_fields($objQuery);
			$resultArray = array();
			while($obResult = mysql_fetch_array($objQuery))
			{
				$arrCol = array();
				for($i=0;$i<$intNumField;$i++)
				{
					$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
				}
				array_push($resultArray,$arrCol);
			}
			
			mysql_close($connection);
			
			echo json_encode($resultArray);
	}else{
	include "../connect2.php";
	$strSQL = "SELECT * FROM userlog INNER JOIN depart ON userlog.departid = depart.departid WHERE 1 AND id_member = '".$_POST["sCusID"]."' AND depart.departid = '$department' ";
	$objQuery = mysql_query($strSQL) or die (mysql_error());
	$intNumField = mysql_num_fields($objQuery);
	$resultArray = array();
	while($obResult = mysql_fetch_array($objQuery))
	{
		$arrCol = array();
		for($i=0;$i<$intNumField;$i++)
		{
			$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
		}
		array_push($resultArray,$arrCol);
	}
	
	mysql_close($connection2);
	
	echo json_encode($resultArray);
	}
?>